package br.rui.servlets;

import javax.servlet.http.HttpServlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.rui.persistencia.ContaDB;

/**
 * Servlet Class
 *
 * @web.servlet              name="Clientes"
 *                           display-name="Name for Clientes"
 *                           description="Description for Clientes"
 * @web.servlet-mapping      url-pattern="/Clientes"
 * @web.servlet-init-param   name="A parameter"
 *                           value="A value"
 */
@SuppressWarnings("serial")
public class Clientes extends HttpServlet {

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException,IOException {
		ContaDB contadb = new ContaDB ();
		String url = null;
		int key = Integer.parseInt(req.getParameter("key"));
		switch (key) {
		case 1:
			url = "/web/jsp/NovaAssoc.jsp";
			break;
		case 2: 
			url = "/web/jsp/ImportPCRui.jsp";
			break;
		case 3: 
			url = "/web/jsp/ImportPCCliente.jsp";
			break;
		default:
			break;
		}
		Collection clientes = contadb.ConsultarClientes();
		req.setAttribute("clientes",clientes);
		RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
		rd.forward(req,resp);
		
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException,IOException {
		doGet(req, resp);
	}

}
